<?php
namespace app\warehouse\controller;
use think\Controller;
use think\Db; 
class Label extends Controller{
    //打印机计算机获取打印任务
    public function get_json(){	
        for($i=1;$i<20;$i++){
            $list = Db::table('label')->find();
            if($list){
                $data = $list;
                $data['code'] = 200;
                Db::table('label')->delete($list['id']);
                echo json_encode($data);
                return ;
            }else{
                usleep(200000); //200MS                      
            }
        }
        $data['code'] = 0;
        echo json_encode($data);
    }
    //编辑标签
    public function edit($pn){	
        //echo $pn;
        if($pn){
            $map['no'] = $pn;
            $item = Db::table('warehouse_item')
            ->where($map)
            ->find();
            
            //var_dump($item);
            $info['type'] = 0;
            $info['pn'] = $item['no'];
            $info['sn'] = "";
            $info['quantity'] = 0;
            $info['model'] = $item['model'];
            $info['name'] = $item['name'];
            $info['text'] = $item['note'];
        }else{
            $info['type'] = 0;
            $info['pn'] = "";
            $info['sn'] = "";
            $info['quantity'] = 0;
            $info['model'] = "";
            $info['name'] = "";
            $info['text'] = "";
        }
        $this->assign('info',$info);
        return view('edit');
    }
    //打印标签
    public function putprint(){	
        $data['type'] = input("post.type");
        $data['pn'] = input("post.pn");
        $data['sn'] = input("post.sn");
        $data['quantity'] = input("post.quantity");
        $data['model'] = input("post.model");
        $data['name'] = input("post.name");
        $data['text'] = input("post.text");
        Db::table('label')->insert($data);//新增
        //返回成功
        $ret['status'] = 1;
        echo json_encode($ret);
    }
}